<template>
	<view>
		<uni-section class="pub-title" title="概览" type="line"></uni-section>
		<uni-card class="card-pub" :title="carInfo.name" :isShadow="true">
			<uni-row>
				<uni-col :span="12">
					我的佣金: {{wodyj / 100}}
				</uni-col>
				<uni-col :span="12">
					团队成员: {{tuandcy}}
				</uni-col>
				<uni-col :span="12">
					出单数: {{chuds}}
				</uni-col>
				<uni-col :span="12">
					出单金额: {{chudje / 100}}
				</uni-col>
			</uni-row>
		</uni-card>

		<uni-section class="pub-title" title="成员列表" type="line"></uni-section>
		<uni-list v-for="(item ,index) in teamList" :key="index">
			<uni-list-item :title="item.username" :note="item.xiaosyj" :thumb="item.avatar" thumb-size="lg"
				rightText="详情" clickable @click="onClick(item)"></uni-list-item>
		</uni-list>

		<div class="clearfix bottom-btn">
			<button type="primary" style="width: 100%" @click="shenqtx"
				class="btn-red border-radius-no fxl">申请提现</button>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wodyj: 0,
				tuandcy: 0,
				chuds: 0,
				chudje: 0,
				teamList: []
			}
		},

		onLoad(option) {
			let that = this

			uni.request({
				url: getApp().globalData.serviceUrl + "/myteam/kuybTeam/list",
				data: {
					parentopenid: uni.getStorageSync("userInfo").openId,
					column: "createTime",
					order: "desc"
				},
				header: {
					"X-Access-Token": uni.getStorageSync("token")
				},
				dataType: 'json',
				method: 'GET',
				success: (result) => {
					if (result.data.success) {
						result.data.result.records.forEach(element => {
							element.xiaosyj = "加入时间: " + element.createTime + " \n出单数: " + element.chuds + " 出单金额: " + element.chudje /
								100

							that.tuandcy++
							that.chuds += element.chuds
							that.chudje += element.chudje
						})

						that.teamList = result.data.result.records
						that.wodyj = that.chudje * 0.5

					}
				}

			});

		},

		methods: {
			shenqtx() {
				let that = this
				
				if (that.wodyj / 100 < 500) {
					uni.showToast({
						title: '提现金额最少要500元!',
						icon: 'none'
					});
					return
				}
				
				uni.request({
					url: getApp().globalData.serviceUrl + "/yongjtix/kuybYongjTix/add",
					data: {
						tixje: that.wodyj
					},
					header: {
						"X-Access-Token": uni.getStorageSync("token")
					},
					dataType: 'json',
					method: 'POST',
					success: (result) => {
						if (result.data.success) {
							uni.showToast({
								title: "提交成功",
								icon: 'none'
							});
							
						} else {
							uni.showToast({
								title: resp.data.message,
								icon: 'none',
								duration: 3000
							});
						}
					}
				});
			},
			
			onClick(item) {
				uni.setStorageSync("memberDetail", item)

				uni.navigateTo({
					url: '../../pages2/chudjl/chudjl'
				})
			}
		}
	}
</script>

<style>

</style>
